Skip to content

Add Expect.oneOf - #126

Merged
Janiczek merged 2 commits into
elm-explorations:masterfrom
sashaafm:add-expect-one-of
Sep 23, 2026
Merged

Janiczek merged 2 commits into
elm-explorations:masterfrom
sashaafm:add-expect-one-of

Conversation

@sashaafm

Copy link
Copy Markdown

This PR adds the Expect.oneOf function. This function works similarly to Expect.all, but results in a pass if at least one of the subjects passes the check. If all subjects fail the check it returns a fail.

I think the implementation should be okay (I had implemented the same function in my codebase, but without the usage of the internal types). I'm not sure about the tests because I'm having a hard time running the repository tests locally.

Any feedback would be appreciated!

Comment thread src/Expect.elm Outdated
[] ->
Test.Expectation.fail
{ reason = Invalid EmptyList
, description = "Expect.oneOf ran out of expectations."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the feedback should be a lot more informative. This doesn't tell you at all how to fix your test.

@sashaafm sashaafm Sep 6, 2023 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gampleman could you please help provide a solution for that? Would it need to keep track of why all expectations failed and print that?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although perhaps in a more condensed format? I think there's some experimentation to be done on this.

@Janiczek
Janiczek merged commit 3f69bb8 into elm-explorations:master Sep 23, 2026
@Janiczek

Copy link
Copy Markdown
Collaborator

Needed a new Failure variant (Multiple), will be a breaking change, but we're already in the phase where we decided we're going for them, so... this is the right time to land this! Thank you @sashaafm for the implementation.

(I've cleaned things up a little bit; one of the other breaking changes is simplifying Expect.all from List (subject -> Expectation) -> subject -> Expectation to List Expectation -> Expectation and keeping the original one under name passesAll, so I did the same for yours oneOf -> passesOneOf.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants